home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
398
/
398.xpi
/
chrome
/
forecastfox.jar
/
content
/
profiles
/
profiles.js
< prev
next >
Wrap
Text File
|
2010-02-04
|
4KB
|
131 lines
/*------------------------------------------------------------------------------
Copyright (c) 2008 Ensolis, LLC. All Rights Reserved.
----------------------------------------------------------------------------*/
var gProfiles = null;
function profilesLoad()
{
gProfiles = new ProfilesModule();
gProfiles.start();
}
function profilesUnload()
{
gProfiles.stop();
gProfiles = null;
}
function ProfilesModule() {}
ProfilesModule.prototype = {
_prfSvc: null,
_type: null,
_bundle: null,
_name: null,
_id: null,
_prompt: null,
start: function ProfilesModule_start()
{
var mgrSvc = Cc["@ensolis.com/forecastfox/manager-service;1"].getService(Ci.ffIManagerService);
this._prfSvc = mgrSvc.profiles;
this._type = window.arguments[0];
this._bundle = document.getElementById("ff-bundle-profiles");
this._name = document.getElementById("ff-text-name");
this._id = document.getElementById("ff-text-id");
//set description
document.getElementById("ff-profiles-header").title = this._bundle.getString("ff.profiles." + this._type);
var item = this._prfSvc.current;
switch (this._type) {
case "create":
this._id.value = this._prfSvc.createID();
this._name.value = "";
break;
case "rename":
this._id.value = item.ID;
this._name.value = item.name;
break;
case "remove":
this._name.readonly = true;
this._id.value = item.ID;
this._name.value = item.name;
break;
}
//set focus
if (this._type != "remove") {
this._name.focus();
this._name.select();
}
},
stop: function ProfilesModule_stop()
{
this._dskSvc = null;
this._prfSvc = null;
this._type = null;
this._bundle = null;
this._id = null;
this._name = null;
this._prompt = null;
},
accept: function ProfilesModule_accept()
{
//get the current list of items
var items = this._prfSvc.getItems({});
var item = this._prfSvc.current;
switch (this._type) {
case "create":
//check that the name is valid
if (this._name.value == "") {
this._alert("ff.profiles.invalid");
return;
}
//add a new profile
var newItem = this._createItem();
this._prfSvc.setItem(newItem);
this._prfSvc.current = newItem;
break;
case "rename":
//check that the name is valid
if (this._name.value == "") {
this._alert("ff.profiles.invalid");
return;
}
//rename the item
item.setProperty("name", this._name.value);
this._prfSvc.setItem(item);
break;
case "remove":
//check that we aren't the last profile
if (items.length == 1) {
this._alert("ff.profiles.last");
return;
}
this._prfSvc.deleteItem(item.ID);
break;
}
window.close();
},
_alert: function ProfilesModule__alert(aText)
{
if (!this._prompt)
this._prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
this._prompt.alert(window, this._bundle.getString("ff.profiles"), this._bundle.getString(aText));
},
_createItem: function ProfilesModule__createItem()
{
var item = this._prfSvc.current.clone();
item.setProperty("ID", this._id.value);
item.setProperty("name", this._name.value);
return item;
}
};